package cn.wolfcode.rbac.util;

import cn.wolfcode.rbac.domain.Employee;
import org.apache.shiro.SecurityUtils;

public class UserContext {

    /**
     *  从 shiro 中，获取当前登录用户
     * @return
     * */
    public static Employee getCurrentUser(){

        return (Employee) SecurityUtils.getSubject().getPrincipal();
    }

   /* public static final String EMPLOYEE_IN_SESSION = "EMPLOYEE_IN_SESSION";
    public static final String PERMISSIONS_IN_SESSION = "PERMISSIONS_IN_SESSION";

    // 抽取成方法（方便）

    // 抽一个方法获取 session
    // 获取 session
    public static HttpSession getSession(){
        // RequestContextHolder 拿到请求相关的上下文 RequestAttributes 接口，所以用实现类，需要强转
        // 使用这个工具RequestContextHolder，就不需要将 session注入进来（简化，方便）
        ServletRequestAttributes requestAttributes =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }

    *//**
     *  从 session中，获取当前登录用户
     * @return
     *//*
    public static Employee getCurrentUser(){

        return (Employee)getSession().getAttribute(EMPLOYEE_IN_SESSION);
    }

    *//**
     *  把用户存到 session中
     * @param employee
     *//*
    public static void setCurrentUser(Employee employee){
        getSession().setAttribute(EMPLOYEE_IN_SESSION,employee);
    }

    *//**
     *  从 session中，获取当前权限用户
     * @return
     *//*
    public static List<String> getCurrentPermissions(){
        return (List<String>)getSession().getAttribute(PERMISSIONS_IN_SESSION);
    }

    *//**
     * 把权限存到 session中
     * @param permissions
     *//*
    public static void setCurrentPermissions(List<String> permissions){
        getSession().setAttribute(PERMISSIONS_IN_SESSION,permissions);
    }*/
}
